package persistence;

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.Transaction;

import entidade.Prato;

public class PratoDao {
	
	protected Criteria cri;
	protected Session session;
	protected Transaction trs;
	
	public void cadastrarPrato(Prato prato)throws Exception{
		session = HibernateUtil.getSessionFactory().openSession();
		trs = session.beginTransaction();
		session.save(prato);
		trs.commit();
		session.close();
	}
		
	@SuppressWarnings("unchecked")
	public List<Prato> consultarPratos() throws Exception{
		session = HibernateUtil.getSessionFactory().openSession();
		trs = session.beginTransaction();
		cri = session.createCriteria(Prato.class);
		return cri.list();
	}
	
	public void atualizarPrato(Prato prato)throws Exception{
		session = HibernateUtil.getSessionFactory().openSession();
		trs = session.beginTransaction();
		session.update(prato);
		trs.commit();
		session.close();
	}
	
	public void deletarPrato(Prato prato)throws Exception{
		session = HibernateUtil.getSessionFactory().openSession();
		trs = session.beginTransaction();
		session.delete(prato);
		trs.commit();
		session.close();
	}

}
